<?php
namespace app\tour\model;

use think\Model;
use think\Db;
use think\Session;

class Album extends Model
{

    /**
     * @param array $field
     * @param array $where
     * @param int $startrow
     * @param int $pageSize
     * @param bool $isCount
     * @return false|int|\PDOStatement|string|\think\Collection
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function albumList($field = array(),$where=array(),$startrow = 0, $pageSize = 0, $isCount = false){

        $tour_id = Session::get('tour_id');

        $query =  Db::name('tour_img')->alias('t1')->field($field)->join('tour_admin t2','t1.t_admin_id = t2.t_admin_id','left')->where('t1.tour_id',$tour_id)->where($where);

        if ($isCount){

            return $query->count();

        }

        if ($pageSize){

            return $query
                 ->order('sort desc,id desc')
                 ->limit($startrow,$pageSize)
                 ->select();

        }

        return $query->select();

    }

    /**
     * @param mixed|string $data
     * @return int|mixed|string
     */
    static function add($data){

        return  Db::name('tour_img')->insertGetId($data);

    }

    /**
     * @param $id
     * @param $editData
     * @return int|string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    static function editAlbum($id,$editData){

        return Db::name('tour_img')->where('id',$id)->update($editData);

    }

}
